/**
 * @param {string} encodedText
 * @param {number} rows
 * @return {string}
 */
 var decodeCiphertext = function(encodedText, rows) {
  const n = encodedText.length, m = n/rows
  const arr = new Array(rows).fill(0).map(() => new Array(m))
  for(let i = 0, k = 0; i<rows; i++){
    for(let j = 0; j<m; j++, k++){
      arr[i][j] = encodedText[k]
    }
  }
  let temp = ''
  for(let i = 0; i<m; i++){
    let x = 0, y = i
    while(x < rows && y < m){
      temp += arr[x][y]
      x++
      y++
    }
  }
  let idx = 0
  for(let i = 0; i<temp.length; i++){
    if(temp[i] !== ' ') idx = i
  }
  return temp.slice(0, idx+1)
};